/*
 * @Description: 
 * @Author: paddies
 * @Date: 2023-12-06 19:30:14
 * @LastEditors: paddies
 * @LastEditTime: 2024-12-16 16:00:21
 * @FilePath: /luntai-user-app/Users/paddies/Desktop/code/A-team/luntai/shared_components/lib/build-checkbox-group/buildCheckBoxGroup.dart
 */
import 'package:flutter/material.dart';

Color disabledColor = Color(0xffa1a1a1);
Widget buildCheckBoxGroup(
    {List list = const [],
    List activeValue = const [],
    bool disabled = false,
    Color activeColor = const Color(0xff0101ec),
    Function? onChange,
    int widthFactor = 4}) {
  return Container(
      width: double.infinity,
      // color: Colors.blue,
      child: Wrap(
          spacing: 0, //主轴上子控件的间距
          runSpacing: 0,
          children: [
            ...list.map((e) {
              return FractionallySizedBox(
                widthFactor: 1 / widthFactor,
                child: Row(
                  children: [
                    Checkbox(
                      value: activeValue.contains(e['value']),
                      activeColor: disabled ? disabledColor : activeColor,
                      onChanged: (v) {
                        if (disabled) {
                          return;
                        }
                        if (disabled == true) {
                          return;
                        }
                        if (onChange != null) {
                          v = v ?? false;
                          onChange(v ? "add" : "del", e['value']);
                        }
                      },
                    ),
                    Expanded(
                        child: GestureDetector(
                            onTap: () {
                              if (disabled == true) {
                                return;
                              }
                              if (onChange != null) {
                                var flag = activeValue.contains(e['value']);
                                onChange(flag ? "del" : "add", e['value']);
                              }
                            },
                            child: Text(
                              e['label'],
                              overflow: TextOverflow.ellipsis,
                            ))),
                  ],
                ),
              );
            }).toList(),
          ]));
}

Color activeBgColor = Color(0xfffdf6f7);
Widget buildNewCheckBoxGroup(
    {List list = const [],
    List activeValue = const [],
    bool disabled = false,
    Color activeColor = const Color(0xffF9110D),
    int maxLines = 1,
    String mode = 'has-broder',
    Function? onChange,
    double fontSize = 14,
    double paddingLeft = 0,
    double paddingRight = 0,
    double paddingTop = 0,
    double paddingBottom = 0,
    int widthFactor = 4}) {
  return Container(
      width: double.infinity,
      padding: EdgeInsets.only(
          left: paddingLeft,
          right: paddingRight,
          top: paddingTop,
          bottom: paddingBottom),
      // color: Colors.blue,
      child: Wrap(
          spacing: 0, //主轴上子控件的间距
          runSpacing: 0,
          children: [
            ...list.map((e) {
              return FractionallySizedBox(
                widthFactor: 1 / widthFactor,
                child: Padding(
                  padding: EdgeInsets.all(5),
                  child: Row(
                    children: [
                      Expanded(
                          child: GestureDetector(
                        onTap: () {
                          if (disabled) {
                            return;
                          }
                          if (disabled == true) {
                            return;
                          }
                          if (onChange != null) {
                            // v = v ?? false;
                            print("改变啦==增加====");
                            print(activeValue.contains(e['value']));
                            onChange(
                                !activeValue.contains(e['value'])
                                    ? "add"
                                    : "del",
                                e['value']);
                          }
                        },
                        child: Container(
                            width: double.infinity,
                            decoration: BoxDecoration(
                                borderRadius: const BorderRadius.all(
                                    Radius.circular(8.0)),
                                color: activeValue.contains(e['value'])
                                    ? activeBgColor
                                    : Color(0xfff7f7f7),
                                border: Border(
                                  left: BorderSide(
                                      width: 1.5,
                                      color: mode == 'has-border'
                                          ? (activeValue.contains(e['value'])
                                              ? activeColor
                                              : Colors.transparent)
                                          : Colors.transparent),
                                  right: BorderSide(
                                      width: 1.5,
                                      color: mode == 'has-border'
                                          ? (activeValue.contains(e['value'])
                                              ? activeColor
                                              : Colors.transparent)
                                          : Colors.transparent),
                                  top: BorderSide(
                                      width: 1.5,
                                      color: mode == 'has-border'
                                          ? (activeValue.contains(e['value'])
                                              ? activeColor
                                              : Colors.transparent)
                                          : Colors.transparent),
                                  bottom: BorderSide(
                                      width: 1.5,
                                      color: mode == 'has-border'
                                          ? (activeValue.contains(e['value'])
                                              ? activeColor
                                              : Colors.transparent)
                                          : Colors.transparent),
                                )),
                            alignment: Alignment.center,
                            padding: EdgeInsets.only(top: 10, bottom: 10),
                            child: Text(
                              e['label'],
                              maxLines: maxLines,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                fontSize: fontSize,
                                fontWeight: FontWeight.bold,
                                color: activeValue.contains(e['value'])
                                    ? activeColor
                                    : disabledColor,
                              ),
                            )),
                      )),
                      // Checkbox(
                      //   value: activeValue.contains(e['value']),
                      //   activeColor: disabled ? disabledColor : activeColor,
                      //   onChanged: (v) {
                      //     if (disabled) {
                      //       return;
                      //     }
                      //     if (disabled == true) {
                      //       return;
                      //     }
                      //     if (onChange != null) {
                      //       v = v ?? false;
                      //       onChange(v ? "add" : "del", e['value']);
                      //     }
                      //   },
                      // ),
                      // Expanded(
                      //     child: GestureDetector(
                      //         onTap: () {
                      //           if (disabled == true) {
                      //             return;
                      //           }
                      //           if (onChange != null) {
                      //             var flag = activeValue.contains(e['value']);
                      //             onChange(flag ? "del" : "add", e['value']);
                      //           }
                      //         },
                      //         child: Text(
                      //           e['label'],
                      //           overflow: TextOverflow.ellipsis,
                      //         ))),
                    ],
                  ),
                ),
              );
            }).toList(),
          ]));
}
